package com.example.juc.kkb.juchelperclass;

import java.util.concurrent.CountDownLatch;

/**
 * CountDownLatch主要有两个⽅法，当⼀个或多个线程调⽤await⽅法时，这些线程会阻塞。
 * 其他线程调⽤countDown⽅法会将计数器减1(调⽤countDown⽅法的线程不会阻塞)，
 * 当计数器的值变为0时，因await⽅法阻塞的线程会被唤醒，继续执⾏
 */
public class CountDownLatchDemo {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(6);
        for (int i = 0; i < 6; i++) {
            System.out.println("同学离开了教室");
            countDownLatch.countDown();
        }
        countDownLatch.await();
        System.out.println(Thread.currentThread().getName() + " 班⻓最后关⻔....");
    }
}